package com.niu.wm.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.niu.wm.service.BaseService;
import com.niu.wm.service.CustomerService;
import com.niu.wm.dao.mapper.CustomerMapper;
import com.niu.wm.model.Customer;
import com.niu.wm.model.User;
import com.niu.wm.form.CustomerSearchForm;
import com.niu.wm.vo.CustomerVO;

@Service
public class CustomerServiceImpl extends BaseService implements CustomerService{

    @Autowired
    private CustomerMapper  customerMapper;
	
	public Customer load(Long id){
		return customerMapper.selectByPrimaryKey(id);
	}
	
	@Transactional
    @Override
	public int insert(User user, Customer customer){
    	customer.setCreatorId(user.getId());    	
    	int count = customerMapper.insert(customer);
    	
    	return count;
	}
    
    @Transactional
    @Override
	public int update(User user, Customer customer){    	
    	return customerMapper.update(customer);
	}
    
    @Transactional
    @Override
	public int delete(User user, Long id) {
		int count = 0;
		customerMapper.delete(id);

		return count;
	}
    
    @Override
	public int countCustomer(CustomerSearchForm form){
    	return customerMapper.countCustomer(form);
    }

    @Override
	public List<CustomerVO> queryCustomer(CustomerSearchForm form, Pageable pageable){
    	List<CustomerVO> list = customerMapper.queryCustomer(form, pageable);
    	
    	return list;
    }
}
